//
//  WidthDrawRecordController.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/9.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class WidthDrawRecordController: BaseViewController,beginRefresh {
    var currentPage : Int = 0
    var table : WidthTableView?
    var noData : NoDataView?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.naviHide = false
        self.title = "提现记录"
        self.defaultBackButton()
        self.view.backgroundColor = UIColor.white
        weak var slf = self
        table = WidthTableView.init(frame: self.view.bounds, delegate: slf!)
        self.view.addSubview(table!)
        noData = NoDataView.init(frame: self.view.bounds)
        noData?.refreshBlock = {
            self.beginRefresh()
        }
        self.view.addSubview(noData!)
        noData?.isHidden = true
        table?.isHidden = true
        beginRefresh()
        // Do any additional setup after loading the view.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //begin refresh
    func beginRefresh() {
        weak var slf = self
        currentPage = 1
        slf?.beginAnim()
        Manager.shared().getWidthDrawRecord(page: String(currentPage), success: {(model) in
            slf?.endAnim()
            if let mod = model as? MineCollectionMessageModel {
                if mod.sourceArr.count > 0 {
                    slf?.noData?.isHidden = true
                    slf?.table?.isHidden = false
                    slf?.table?.feedData(model: mod)
                } else {
                    slf?.noData?.isHidden = false
                    slf?.table?.isHidden = true
                    slf?.noData?.endRefresh()
                }
            }
        }, fail: {(code)in
            slf?.endAnim()
            slf?.noData?.endRefresh()
            slf?.commonAlertMsg(content: YXNetWorkFail)
        })
    }
    
    func loadNext() {
        currentPage += 1
        weak var slf = self
        table?.beginAppend()
        Manager.shared().getWidthDrawRecord(page: "2", success: {(model) in
            if let mod = model as? MineCollectionMessageModel {
                slf!.table?.appendData(model: mod)
            }
        }, fail: {(code) in
            slf!.commonAlertMsg(content: YXNetWorkFail)
        })
    }
}
